onmessage = function(e) {
	importScripts("vw.static.js");

	var data = e.data.data;
	var columns = e.data.columns;
	var source = e.data.source;
	var idField = e.data.idField;

	for(var i = 0; i < data.length; i++) {
		for(var k in columns) {
			var column = columns[k];
			if(column.title == "-" || column.title == idField || column.disable || !column.visible) {
				continue;
			}

			var hasCol = false;
			for(var field in data[i]) {
				if(field == column.title) {
					hasCol = true;
					var msg = vw_static.customValidate(column, data[i][field]);
					if(msg) {
						post(i, field, msg);
						break;
					} else if(column.type == "select" || column.type == "select2") {
						if(!data[i][field]) {
							data[i][field] = "";
						}
						var vals = data[i][field].toString().split(",");
						if(vals.length == 1 && !vals[0]) {
							if(!column.cannull) {
								post(i, field, "枚举字段内容为空");
							}
							break;
						}
						if(source[field]) {
							var checked = false;		
							for(var key in source[field]) {
								if(vals.indexOf(key) > -1) {
									checked = true;
									break;
								}
							}
							if(!checked) {
								post(i, field, "内容不在枚举值范围内");
								break;
							}
						} else {
							if(data[i][field]) {
								post(i, field, "未设置枚举项");
								break;
							}
						}
					} else if(!data[i][field] && data[i][field] !== 0 && !column.cannull) {
						post(i, field, "字段内容为空");
						break;
					} else {
						break;
					}
				}
			}

			if(!hasCol && !column.cannull) {
				post(i, column.title, "字段内容为空");
			}
		}

		postMessage({
			id: i
		})
	}

	function post(i, field, msg) {
		postMessage({
			id: i,
			data: {
				id: i,
				row: data[i][idField],
				col: field,
				val: data[i][field],
				msg: msg
			}
		});
	}
};